package com.队列;

/**
 * 循环队列
 */
public class MyCircularQueue {
    private int[] data; //队列
    private int head; //头
    private int tail; //尾
    private int size; //容量

    /** Initialize your data structure here. Set the size of the queue to be k. */
    public MyCircularQueue(int k) {
       data = new int[5];
        size = k;
        head = -1;
        tail = -1;
    }

    /** 入队 */
    public boolean enQueue(int value) {
       if(isFull()){
           return    false;
       }
       head = 0;
       tail = (tail + 1)%size;
       data[tail] = value;
       return true;
    }

    /** 出队. */
    public boolean deQueue() {
        if(isEmpty()){
            return  false;
        }
        data[head] = 0;
        if(head == tail){
            head = -1;
            tail = -1;
            return  true;
        }
        head = (head + 1) %size;
        return true;

    }

    /** 队头 */
    public int Front() {
        if(isEmpty()){
            return  -1;
        };
        return data[head];
    }
    /** 队尾. */
    public int Rear() {
        if(isEmpty()){

            return  -1;
        }
        return data[tail];
    }

    /** 检查空队列. */
    public boolean isEmpty() {
           return head == -1;
    }

    /** 检查满队列 */
    public boolean isFull() {
        return (tail + 1) % size == head;
    }

    @Override
    public String toString() {
       return "";
    }

    public static void main(String[] args) {

    }
}
